<template>
  <!-- 系统目录 西成药品 -->
  <div class="MedicenCata">
    <div class="compact-form-box">
      <el-tabs type="border-card" style="height: 100%">
        <el-tab-pane label="患者信息">
          <el-form :model="queryConditionForm" label-width="90px" size="mini" class="responsive-form">
            <el-row :gutter="8" class="form-row">
              <!-- 健康ID -->
              <el-col :xs="24" :sm="12" :md="6" :lg="4" :xl="3">
                <el-form-item label="健康ID:" class="compact-form-item">
                  <el-input
                      v-model="queryConditionForm.patId"
                      placeholder="请输入"
                      @keyup.enter.native="handleSearch"
                      class="full-width-input"
                  ></el-input>
                </el-form-item>
              </el-col>

              <!-- 时段筛选 -->
              <el-col :xs="24" :sm="12" :md="6" :lg="4" :xl="3">
                <el-form-item label="时段筛选:" class="compact-form-item">
                  <el-select
                      v-model="queryConditionForm.timeFrame"
                      placeholder="请选择"
                      @change="handleTimeChange"
                      class="full-width-select"
                  >
                    <el-option
                        v-for="item in timeOption"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <!-- 时间范围 -->
              <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="6">
                <el-form-item label="时间范围:" class="compact-form-item">
                  <div class="date-range-container">
                    <el-date-picker
                        v-model="queryConditionForm.timeFrameArr[0]"
                        type="datetime"
                        placeholder="开始时间"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        :picker-options="pickerOptionsStart"
                        @change="handleConditionQuery"
                        class="date-picker"
                    ></el-date-picker>
                    <span class="date-separator">-</span>
                    <el-date-picker
                        v-model="queryConditionForm.timeFrameArr[1]"
                        type="datetime"
                        placeholder="结束时间"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        :picker-options="pickerOptionsEnd"
                        @change="handleConditionQuery"
                        class="date-picker"
                    ></el-date-picker>
                  </div>
                </el-form-item>
              </el-col>

              <!-- 状态 -->
              <el-col :xs="24" :sm="12" :md="6" :lg="3" :xl="3">
                <el-form-item label="状态:" class="compact-form-item">
                  <el-select
                      v-model="queryConditionForm.executeState"
                      placeholder="请选择"
                      @change="loadData"
                      class="full-width-select"
                  >
                    <el-option
                        v-for="item in executeStateOption"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <!-- 执行时间 -->
              <el-col :xs="24" :sm="12" :md="6" :lg="4" :xl="3">
                <el-form-item label="执行时间:" class="compact-form-item">
                  <el-date-picker
                      v-model="queryConditionForm.executeTime"
                      type="date"
                      placeholder="选择日期"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      @change="handleGetExeDetailByDate"
                      class="full-width-date-picker"
                  />
                </el-form-item>
              </el-col>

              <!-- 类别 -->
              <el-col :xs="24" :sm="12" :md="6" :lg="4" :xl="3">
                <el-form-item label="类别:" class="compact-form-item">
                  <el-select
                      v-model="queryConditionForm.executeType"
                      placeholder="请选择"
                      @change="loadData"
                      class="full-width-select"
                  >
                    <el-option
                        v-for="item in executeTypeOption"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <!-- 科室 -->
              <el-col :xs="24" :sm="12" :md="6" :lg="4" :xl="3">
                <el-form-item label="科室:" class="compact-form-item">
                  <el-select
                      v-model="queryConditionForm.deptId"
                      placeholder="请选择"
                      @change="loadData"
                      clearable
                      class="full-width-select"
                  >
                    <el-option
                        v-for="item in deptOptions"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </div>

    <div class="medical-system-container">
      <!-- 1. 主表格区域 -->
      <div class="table-main-container">
        <!-- 左侧标签页 -->
        <div class="left-tabs-container">
          <el-tabs type="border-card" class="left-tabs">
            <el-tab-pane label="待执行列表">
              <div class="table-container">
                <el-table
                    height="100%"
                    :data="tableData1"
                    border
                    @row-click="handleRowClick"
                    highlight-current-row>
                  <!-- 原有列定义保持不变 -->
                  <el-table-column fixed="left" label="行号" type="index" width="50" align="center"></el-table-column>
                  <el-table-column
                      v-for="(col, inx) in tableRows1"
                      :key="inx"
                      :type="col.type"
                      :prop="col.prop"
                      :label="col.name"
                      align="center"
                      :render-header="labelHead"
                      :min-width="getColumnWidth(col.label,col.prop,tableData1)">
                    <template #default="{ row }">
                      {{ safeGetMappedValue(col, row) }}
                    </template>
                  </el-table-column>
                  <el-table-column fixed="right" label="操作" width="90" align="center" header-align="center">
                    <template #default="scope">
                      <el-button
                          size="mini"
                          type="warning"
                          :disabled="scope.row.state === 1"
                          @click.stop="handleDisableExeTable(scope.row)"
                      >
                        {{ scope.row.state === 1 ? '已退费' : '退费' }}
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <!-- 右侧标签页区域 -->
        <div class="right-tabs-container">
          <el-tabs type="border-card" class="right-tabs" v-model="therapyManage">
            <!-- 标签页1: 基本信息 -->
            <el-tab-pane label="基本信息" name="basic">
              <div class="info-form white-bg">
                <el-form :model="patientForm" label-width="90px" size="mini" class="compact-form five-col-form"
                         style="margin-bottom: 0;" disabled>
                  <!-- 第一行 - 基本信息 -->
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="5">
                      <el-form-item label="健康ID:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.patId" size="mini"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="姓名:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.name" size="mini" :disabled="isInputDisabled"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="性别:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.sex" size="mini">
                          <el-option v-for="item in sexOption" :key="item.id" :label="item.label" :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="出生日期:" class="compact-item nowrap-label">
                        <el-date-picker v-model="patientForm.brdy" type="date" size="mini" value-format="yyyy-MM-dd"
                                        style="width: 100%"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="年龄:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.ageYear" size="mini" style="width: 100%"/>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 第二行 - 联系信息 -->
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="5">
                      <el-form-item label="婚姻:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.mrgState" size="mini">
                          <el-option v-for="item in mrgStateEntitiesOptions" :key="item.id" :label="item.label"
                                     :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="病员类型:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.prhType" size="mini">
                          <el-option v-for="item in prhTypeOption" :key="item.id" :label="item.label" :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="职业:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.jobId" size="mini" filterable clearable>
                          <el-option v-for="item in jobOption" :key="item.id" :label="item.label" :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="本人电话:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.tel" size="mini"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="联系人:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.conerName" size="mini"/>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 第三行 - 联系信息 -->
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="5">
                      <el-form-item label="联系电话:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.conerTel" size="mini"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="联系人关系:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.conerRltsId" size="mini" filterable clearable>
                          <el-option v-for="item in rltsEntitiesOption" :key="item.id" :label="item.label"
                                     :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <!--                    <el-col :span="5">
                                          <el-form-item label="工作单位:" class="compact-item nowrap-label">
                                            <el-select v-model="patientForm.phrUnt" size="mini">
                                              <el-option v-for="item in contractUnitOption" :key="item.id" :label="item.label"
                                                         :value="item.id"/>
                                            </el-select>
                                          </el-form-item>
                                        </el-col>-->
                  </el-row>
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="5">
                      <el-form-item label="身高:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.bodyHeight" size="mini"/>
                          <span class="unit">CM</span>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="体重:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.bodyWeight" size="mini"/>
                          <span class="unit">KG</span>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="体温:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.bodyTemperature" size="mini"/>
                          <span class="unit">°C</span>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="呼吸:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.breathe" size="mini"/>
                          <span class="unit">次/分钟</span>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="脉搏:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.pulse" size="mini"/>
                          <span class="unit">次/分钟</span>
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 第六行 - 其他信息 -->
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="5">
                      <el-form-item label="血压:" class="compact-item nowrap-label">
                        <div class="blood-pressure">
                          <el-input v-model="patientForm.syspre" size="mini" style="width: 45%"/>
                          <span class="divider">/</span>
                          <el-input v-model="patientForm.diapre" size="mini" style="width: 45%"/>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="血糖值:" class="compact-item nowrap-label">
                        <div class="with-unit">
                          <el-input v-model="patientForm.bloodNumber" size="mini"/>
                          <span class="unit">mmol/L</span>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="过敏原:" class="compact-item nowrap-label">
                        <el-select v-model="patientForm.allergen" size="mini" filterable clearable>
                          <el-option v-for="item in aiseListOptions" :key="item.id" :label="item.label"
                                     :value="item.id"/>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="24">
                      <el-form-item label="诊断:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.diagnostics" size="mini"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="24">
                      <el-form-item label="联系地址:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.conerAddName" size="mini"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="24">
                      <el-form-item label="患者信息:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.bodyHeight" size="mini"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="12" class="form-row">
                    <el-col :span="24">
                      <el-form-item label="医嘱内容:" class="compact-item nowrap-label">
                        <el-input v-model="patientForm.medicalAdviceContent" size="mini"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </el-tab-pane>

            <el-tab-pane label="治疗管理" name="treatment" v-if="stayExecutionList.exeType === 4">
              <div class="treatment-container">
                <!-- 上方主表格 (70%) -->
                <div class="treatment-main-table">
                  <div class="table-wrapper">
                    <el-table
                        ref="singleSelectTable"
                        height="100%"
                        :data="tableData2"
                        border
                        @row-click="handleCurrentRow"
                        @select="handleSelectionChange"
                        highlight-current-row
                        style="width: 100%; min-width: fit-content">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>

                      <el-table-column
                          v-for="(col, inx) in tableRows5"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          align="center"
                          :render-header="labelHead"
                          :min-width="getColumnWidth(col.label,col.prop,tableData2)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>

                <!-- 下方明细表格 (30%) -->
                <div class="treatment-detail-table">
                  <div class="table-wrapper">
                    <el-table
                        height="100%"
                        :data="tableData3"
                        border
                        highlight-current-row
                        @row-click="handleCurrentExecuteDetailRow"
                        style="width: 100%">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>
                      <el-table-column
                          v-for="(col, inx) in tableRows9"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          :render-header="labelHead"
                          align="center"
                          :min-width="getColumnWidth(col.label,col.prop,tableData2)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-tab-pane>

            <el-tab-pane label="皮试管理" name="skinTest" v-if="stayExecutionList.exeType === 3">
              <div class="treatment-container">
                <!-- 上方主表格 (70%) -->
                <div class="treatment-main-table">
                  <div class="table-wrapper">
                    <el-table
                        ref="singleSelectTable"
                        height="100%"
                        :data="tableData2"
                        border
                        @row-click="handleCurrentRow"
                        @select="handleSelectionChange"
                        highlight-current-row
                        style="width: 100%; min-width: fit-content">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>

                      <el-table-column
                          v-for="(col, inx) in tableRows5"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          align="center"
                          :render-header="labelHead"
                          :min-width="getColumnWidth(col.label,col.prop,tableData2)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>

                <!-- 下方明细表格 (30%) -->
                <div class="treatment-detail-table">
                  <div class="table-wrapper">
                    <el-table
                        height="100%"
                        :data="tableData3"
                        border
                        highlight-current-row
                        @row-click="handleCurrentExecuteDetailRow"
                        style="width: 100%">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>
                      <el-table-column
                          v-for="(col, inx) in tableRows8"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          :render-header="labelHead"
                          align="center"
                          :min-width="getColumnWidth(col.label,col.prop,tableData3)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-tab-pane>

            <el-tab-pane label="输液注射管理" name="intravenousInfusion"
                         v-if="[1,2].includes(stayExecutionList.exeType)">
              <div class="treatment-container">
                <!-- 上方主表格 (70%) -->
                <div class="treatment-main-table">
                  <div class="table-wrapper">
                    <el-table
                        ref="singleSelectTable"
                        height="100%"
                        :data="tableData2"
                        border
                        @row-click="handleCurrentRow"
                        @select="handleSelectionChange"
                        highlight-current-row
                        style="width: 100%; min-width: fit-content">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>

                      <el-table-column
                          v-for="(col, inx) in tableRows6"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          align="center"
                          :render-header="labelHead"
                          :min-width="getColumnWidth(col.label,col.prop,tableData2)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>

                <!-- 下方明细表格 (30%) -->
                <div class="treatment-detail-table">
                  <div class="table-wrapper">
                    <el-table
                        height="100%"
                        :data="tableData3"
                        border
                        highlight-current-row
                        @row-click="handleCurrentExecuteDetailRow"
                        style="width: 100%">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>
                      <el-table-column
                          v-for="(col, inx) in tableRows7"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          :render-header="labelHead"
                          align="center"
                          :min-width="getColumnWidth(col.label,col.prop,tableData3)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-tab-pane>

            <el-tab-pane label="煎药管理" name="boilMedicine"
                         v-if="stayExecutionList.exeType === 5">
              <div class="treatment-container">
                <!-- 上方主表格 (70%) -->
                <div class="treatment-main-table">
                  <div class="table-wrapper">
                    <el-table
                        ref="singleSelectTable"
                        height="100%"
                        :data="tableData2"
                        border
                        @row-click="handleCurrentRow"
                        @select="handleSelectionChange"
                        highlight-current-row
                        style="width: 100%; min-width: fit-content">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>

                      <el-table-column
                          v-for="(col, inx) in tableRows6"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          align="center"
                          :render-header="labelHead"
                          :min-width="getColumnWidth(col.label,col.prop,tableData2)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>

                <!-- 下方明细表格 (30%) -->
                <div class="treatment-detail-table">
                  <div class="table-wrapper">
                    <el-table
                        height="100%"
                        :data="tableData3"
                        border
                        highlight-current-row
                        @row-click="handleCurrentExecuteDetailRow"
                        style="width: 100%">
                      <!-- 表格列定义 -->
                      <el-table-column fixed="left" label="行号" type="index" width="50"
                                       align="center"></el-table-column>
                      <el-table-column
                          v-for="(col, inx) in tableRows7"
                          :key="inx"
                          :type="col.type"
                          :prop="col.prop"
                          :label="col.name"
                          :render-header="labelHead"
                          align="center"
                          :min-width="getColumnWidth(col.label,col.prop,tableData3)">
                        <template #default="{ row }">
                          <span class="cell-content">{{ safeGetMappedValue(col, row) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-tab-pane>

            <!--             费用记账
                        <el-tab-pane label="费用记账" name="billing">
                          <div class="table-container">
                            <el-table
                                height="100%"
                                :data="tableData4"
                                border
                                show-summary
                                :summary-method="getSummaries"
                                @row-click="handleCurrentRow"
                                @row-dblclick="handleDbShowChargeDetail"
                                highlight-current-row>
                              &lt;!&ndash; 表格列定义 &ndash;&gt;
                              <el-table-column
                                  v-for="(col, inx) in tableRows4"
                                  :key="inx"
                                  :type="col.type"
                                  :prop="col.prop"
                                  :label="col.name"
                                  align="center"
                                  :render-header="labelHead"
                                  :min-width="getColumnWidth(col.label,col.prop,tableData4)">
                              </el-table-column>
                            </el-table>
                          </div>
                        </el-tab-pane>-->
          </el-tabs>
        </div>
      </div>
      <div class="bottom-control-form" style="display: flex; align-items: center; justify-content: space-between;">
        <!-- 分页控件（左对齐） -->
        <el-pagination
            style="margin: 0;"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[12, 24, 48]"
            :page-size="pageSize"
            :total="totalSize"
            layout="total, sizes, prev, pager, next, jumper"
            background
        />

        <!-- 操作按钮组（右对齐） -->
        <div class="button-group">
          <div class="action-buttons">
            <el-button
                :disabled="stayExecutionList.state === 1"
                v-for="(btn, index) in actionButtons"
                :key="index"
                :type="btn.type"
                size="small"
                @click="btn.action">
              {{ btn.text }}
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!--选择皮试结果-->
    <el-dialog
        :close-on-click-modal="false"
        title="选择皮试结果"
        :visible.sync="selSkinTestResultDialogVisible"
        width="20%"
        :before-close="handleCloseSelSkinTest">

      <el-form size="mini" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="结束时间:" prop="endDateTime">
              <el-date-picker
                  v-model="planDateTime.endDateTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择结束时间"
                  style="width: 100%">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="皮试结果:">
              <el-select
                  filterable
                  v-model="exeSkintstType"
                  style="width: 100%"
                  placeholder="请选择皮试结果">
                <el-option
                    v-for="item in skinTestOption"
                    :key="item.id"
                    :label="item.label"
                    :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer no-line">
    <el-button @click="handleCloseSelSkinTest" size="mini">取消</el-button>
    <el-button type="primary" @click="exePlanSTEdit" size="mini">确定</el-button>
  </span>
    </el-dialog>

    <el-dialog
        :close-on-click-modal="false"
        title="修改时间"
        :visible.sync="editDateTimeDialogVisible"
        width="20%"
        :before-close="handleCloseEditDate">
      <el-form
          :model="planDateTime"
          ref="timeForm"
          size="mini"
          label-width="100px"
          class="time-picker-form">
        <el-row>
          <el-col :span="24">
            <el-form-item label="开始时间:" prop="startDateTime">
              <el-date-picker
                  v-model="planDateTime.startDateTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择开始时间"
                  style="width: 100%"
                  @change="handleStartTimeChange">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="结束时间:" prop="endDateTime">
              <el-date-picker
                  v-model="planDateTime.endDateTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择结束时间"
                  style="width: 100%"
                  @change="handleEndTimeChange">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="皮试结果:">
              <el-select
                  filterable
                  v-model="planDateTime.exeSkintstType"
                  style="width: 100%"
                  placeholder="请选择皮试结果">
                <el-option
                    v-for="item in skinTestOption"
                    :key="item.id"
                    :label="item.label"
                    :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer no-line">
      <el-button @click="handleCloseEditDate" size="mini">取消</el-button>
      <el-button type="primary" @click="submitDateTime" size="mini">确定</el-button>
    </span>
    </el-dialog>

    <el-dialog
        :close-on-click-modal="false"
        title="执行时间"
        :visible.sync="planDateTimeDialogVisible"
        width="20%"
        :before-close="handleClosePlanDate">

      <el-form
          :model="planDateTime"
          ref="timeForm"
          size="mini"
          label-width="100px"
          class="time-picker-form">

        <el-row>
          <el-col :span="24">
            <el-form-item label="执行时间:" prop="startDateTime">
              <el-date-picker
                  v-model="planDateTime.startDateTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择执行时间"
                  :clearable="false"
                  style="width: 100%"
                  :picker-options="{
    disabledDate: time => {
      const now = new Date();
      const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
      return time.getTime() < today.getTime();
    }
  }">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer no-line">
    <el-button @click="handleClosePlanDate" size="mini">取消</el-button>
    <el-button type="primary" @click="handleExecutionPlan" size="mini">确定</el-button>
  </span>
    </el-dialog>

    <el-dialog
        title="患者选择"
        :visible.sync="patientDialogVisible"
        width="60%"
        :before-close="handleCloseChoosePatient"
        class="patient-dialog"
    >
      <!-- 患者表格 - 固定高度，超出部分滚动 -->
      <el-table
          :data="patientTabelData"
          border
          highlight-current-row
          @row-dblclick="handleChoosePatient"
          @current-change="handleClickRow"
          style="width: 100%;"
          height="400px"
      >
        <el-table-column v-for="(col, inx) in tableRows14" :key="inx" :type="col.type" :prop="col.prop"
                         :label="col.name" :render-header="labelHead" align="center"
                         :min-width="getColumnWidth(col.label,col.prop,patientTabelData)">
          <template #default="{ row }">
            {{ safeGetMappedValue(col, row) }}
          </template>
        </el-table-column>
      </el-table>

      <div class="dialog-footer no-line">
        <el-button type="primary" @click="handleChoosePatient" size="mini" :loading="loading">确定</el-button>
        <el-button @click="handleCloseChoosePatient" size="mini">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {dict, getContuntList, getDeptList} from "@/api/reservation/reservation";
import AddType from './reservationAddType.js'
import {
  getAiseList,
  getChinaPrescription,
  getDocphrByCondtion,
  getDocphrList,
  getDoctoradvice,
  getDoctordispose,
  getReceptionDiagnosis,
  getWestPrescription
} from "@/api/reservation/outpatientPhysician";
import {getDosaUnt, getMedicationWay} from "@/api/MedicenCata";
import dayjs from "dayjs";
import AddressSelector from "@/views/reservation/AddressSelector.vue";
import {
  cancelExePlan,
  disableExeTable,
  executionPlan,
  exePlanSTEdit,
  getExeDetail,
  getExePlanList,
  getExetableList,
  getSeedoctorById
} from "@/api/reservation/outpatientNurse";
import {withLoading} from "@/untils/loading";
import printUtil from "@/untils/printUtil";
import {identityCard} from "@/assets/printTemplateConfig/identityCard";
import {bottleLabel} from "@/assets/printTemplateConfig/bottleLabel";
import {infusionCard} from "@/assets/printTemplateConfig/infusionCard";
import {getDoctorList} from "@/api/scheduling/scheduling";

export default {
  components: {AddressSelector},
  data() {

    return {
      pickerOptionsStart: {
        // 允许选择任何时间（包括过去时间）
        disabledDate: () => false, // 不禁用任何日期
      },
      pickerOptionsEnd: {
        disabledDate: (time) => {
          // 如果选择了开始时间，则结束时间不能早于它
          if (this.queryConditionForm.timeFrameArr?.[0]) {
            return dayjs(time).isBefore(dayjs(this.queryConditionForm.timeFrameArr[0]));
          }
          return false;
        }
      },
      therapyManage: 'treatment',

      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = dayjs();
            const start = end.subtract(1, 'week');
            picker.$emit('pick', [
              start.format('YYYY-MM-DD HH:mm:ss'),
              end.format('YYYY-MM-DD HH:mm:ss')
            ])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = dayjs();
            const start = end.subtract(1, 'month');
            picker.$emit('pick', [
              start.format('YYYY-MM-DD HH:mm:ss'),
              end.format('YYYY-MM-DD HH:mm:ss')
            ])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = dayjs();
            const start = end.subtract(3, 'month');
            picker.$emit('pick', [
              start.format('YYYY-MM-DD HH:mm:ss'),
              end.format('YYYY-MM-DD HH:mm:ss')
            ])
          }
        }, {
          text: '今天',
          onClick(picker) {
            const start = dayjs().startOf('day');
            const end = dayjs().endOf('day');
            picker.$emit('pick', [
              start.format('YYYY-MM-DD HH:mm:ss'),
              end.format('YYYY-MM-DD HH:mm:ss')
            ])
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const start = dayjs().subtract(1, 'day').startOf('day');
            const end = dayjs().subtract(1, 'day').endOf('day');
            picker.$emit('pick', [
              start.format('YYYY-MM-DD HH:mm:ss'),
              end.format('YYYY-MM-DD HH:mm:ss')
            ])
          }
        }]
      },

      //控制变量
      showDetails: true,//表格明细
      showPrescriptionDetails: true,//处方表格明细
      patientDialogVisible: false,//患者选择弹窗
      loading: false,//加载圈
      isInputDisabled: false,//置灰健康ID
      celerityFilingDialogVisible: false,//快速建档弹窗
      settleAccountsDialogVisible: false,//门诊支付弹窗
      onCreditDialogVisible: false,//选择挂账类型弹窗
      addOnCreditDialogVisible: false,//新增挂账类型弹窗
      addUnitModalVisible: false, // 合约单位弹出框
      hasInitTable0: false, // 区分中西处方
      hasInitTable1: false, // 区分中西处方
      patientFormDisabled: false,//患者表单置灰
      showChargeDtailDialog: false,//查看收费处方详情
      selSkinTestResultDialogVisible: false,//选择皮试结果
      editDateTimeDialogVisible: false,//修改时间
      planDateTimeDialogVisible: false,//执行时间
      portionRefundDialogVisible: false,//部分零退
      currentRow: null,//选中的明细当前行0 处置项目 1 西药 2 中药 3 检查 4 检验5快速就诊(Bus_id对应医嘱id)
      currentDetailTableData: null,//动态表格数据
      currentFeeType: null,  //记录当前行的 feeType
      clickDebounceTimer: null,//防抖计时器
      exeSkintstType: null,//皮试结果
      stayExecutionList: {},//待执行列表单击数据
      currentExecuteDetailData: null,//执行明细单击数据
      //表格数据容器
      patientTabelData: [],//选择患者表格
      tableData1: [],//左表格数据
      tableData2: [],//右表格治疗管理上
      tableData3: [],//右表格治疗管理下
      tableData4: [],//费用记账
      tableData5: [],//
      currentExecuteData: null,//治疗管理单击选中
      pageNum: 1, //当前页currentPage
      pageSize: 12,
      totalSize: null, //总条数
      //下拉框容器
      provinces: [],  // 所有省份
      cityOption: [],     // 当前省下的城市
      countyOption: [],    // 当前市下的区县
      townOption: [],    // 区县下的乡
      villageOption: [],    // 区县下的乡
      prhCostOption: [],//病员费别
      prhTypeOption: [],//病员类别
      rltsEntitiesOption: [],//联系人关系
      contractUnitOption: [],//合约单位
      onCreditOption: [],//挂账类型
      untAtteOption: [],//往来单位新增---单位属性
      deptOptions: [],//科室下拉框
      doctorOptions: [],//医生下拉框
      chargingPriceOptions: [],//项目价格下拉框
      registerOptions: [],//挂号类别
      ntlyOptions: [],//国籍
      mrgStateEntitiesOptions: [],//婚姻
      medicationFrequencyOptions: [],//用药频率
      medicationWayOptions: [],//给药方式
      dosaUntOptions: [],//单位
      addUnitType: [], //合约单位动态表单
      nationOption: [],//民族下拉框
      certypeOption: [],//证件下拉框
      profttlOption: [],//职称下拉框
      jobOption: [],//职业下拉框
      aiseListOptions: [],//过敏原
      ticketTypeOption: [{id: 1, label: '普通门诊发票'}],
      skinTestOption: [{id: 0, label: '阴性'}, {id: 1, label: '阳性'}],
      sexOption: [{id: 1, label: '男'}, {id: 2, label: '女'}],
      orderTypeOptions: [{id: 0, label: '西药处方费'}, {id: 1, label: '中药处方费'}, {id: 2, label: '检查费'}, {
        id: 3,
        label: '检验费'
      }, {id: 4, label: '处置项目费'}, {id: 5, label: '快速就诊'}],
      stateOption: [{id: 0, label: '禁用'}, {id: 1, label: '可用'}],
      executeStateOption: [{id: 0, label: '全部'}, {id: 1, label: '待执行'}, {id: 2, label: '已执行'}, {
        id: 3,
        label: '已停止'
      }],
      executeTypeOption: [{id: 0, label: '全部'}, {id: 1, label: '注射'}, {id: 2, label: '输液'}, {
        id: 3,
        label: '皮试'
      }, {id: 4, label: '治疗'}, {id: 5, label: '物品'}],
      nuyStateOption: [{id: 0, label: '否'}, {id: 1, label: '冲销原单'}, {id: 2, label: '冲销负单'}],
      opeWayOption: [{id: 0, label: '现场'}, {id: 1, label: '网络'}, {id: 2, label: '自助机'}, {
        id: 3,
        label: '银医通'
      }],
      busFormOption: [{id: 0, label: '医嘱'}, {id: 1, label: '手工'}, {id: 2, label: '护理'}, {id: 3, label: '网络'}],
      feeTypeOption1: [{id: 0, label: '处置项目'}, {id: 1, label: '西药费'}, {id: 2, label: '中药费'}, {
        id: 3,
        label: '检查'
      }, {id: 4, label: '检验'}, {id: 5, label: '快速就诊'}],
      timeOption: [{id: 0, label: '选择今天'}, {id: 1, label: '选择昨天'}, {id: 2, label: '选择上月'}, {
        id: 3,
        label: '选择本月'
      }, {id: 4, label: '会计期间'}, {id: 5, label: '选择本年'}, {id: 6, label: '统计上午'}, {
        id: 7,
        label: '统计下午'
      }, {id: 8, label: '统计晚上'},],
      exeTypeOptions: [{id: 1, label: '注射'}, {id: 2, label: '输液'}, {id: 3, label: '皮试'}, {
        id: 4,
        label: '治疗'
      }, {id: 5, label: '煎药'}],
      sexOptions: [{id: 1, label: '男'}, {id: 2, label: '女'}],
      isChargeOptions: [{id: 0, label: '否'}, {id: 1, label: '是'}],
      busFromOptions: [{id: 1, label: '西药'}, {id: 2, label: '中药'}, {id: 3, label: '皮试'}, {
        id: 4,
        label: '治疗'
      }, {id: 5, label: '其他'}],
      feeNoOptions: [{id: 0, label: '否'}, {id: 1, label: '是'}],
      isPrintOptions: [{id: 0, label: '否'}, {id: 1, label: '是'}],
      getMedicineStateOptions: [{id: 0, label: '草稿'}, {id: 1, label: '已收费'}, {id: 2, label: '已配药'}, {
        id: 3,
        label: '已发药'
      }, {id: 4, label: '已退药'}, {id: 99, label: ' '}],
      // 表格动态列
      tableRows1: [
        {name: "执行类型", prop: "exeType", op: 'exeTypeOptions'},
        {name: "医嘱内容", prop: "drordName"},
        {name: "姓名", prop: "name"},
        {name: "性别", prop: "sex", op: 'sexOptions'},
        {name: "年龄", prop: "age"},
        {name: "出生日期", prop: "brdy"},
        {name: "开单医生", prop: "bilgDrName"},
        {name: "执行数量", prop: "exeCnt"},
        {name: "已执行数量", prop: "reptdCnt"},
        {name: "执行科室", prop: "exeDeptId", op: 'deptOptions'},
        {name: "执行人", prop: "exeUserName"},
        {name: "执行频率", prop: "exeFrquId", op: 'medicationFrequencyOptions'},
        {name: "业务来源", prop: "busFrom", op: 'busFromOptions'},
        {name: "周期天数", prop: "prdDays"},
        {name: "业务序号", prop: "busId"},
        {name: "处方序号", prop: "rxId"},
        {name: "收费序号", prop: "feeId"},
      ],
      tableRows2: [
        {name: "是否收费", prop: "feeNo", op: 'feeNoOptions'},
        {name: "业务来源", prop: "busFrom", op: 'busFromOptions'},
        {name: "医嘱内容", prop: "drordName"},
        {name: "数量", prop: "cnt"},
        {name: "应执行日期", prop: "exeDate"},
        {name: "执行频率", prop: "exeFrquId", op: 'medicationFrequencyOptions'},
        /*{name: "执行数量", prop: "cnt"},*/
        {name: "已执行数量", prop: "reptdCnt"},
        {name: "医嘱备注", prop: "drordRemarks"},
        {name: "取药否", prop: "sendState", op: 'getMedicineStateOptions'},
        {name: "输液速度", prop: "speed"},
        {name: "周期天数", prop: "prdDays"},
      ],

      tableRows3: [
        {name: "执行科室", prop: "exeDeptId", op: 'deptOptions'},
        {name: "执行人", prop: "exeUserName"},
        {name: "操作人", prop: "exeUserName"},
        {name: "执行时间", prop: "exeDatetime"},
        {name: "操作时间", prop: "createTime"},
        {name: "输液单打印", prop: "infusionPrint", op: 'isPrintOptions'},
        {name: "瓶签打印", prop: "labelPrint", op: 'isPrintOptions'},
        {name: "输液单打印时间", prop: "infusionTime"},
        {name: "瓶签打印时间", prop: "labelTime"},
        {name: "执行明细序号", prop: "nursDetId"},
      ],
      tableRows4: [
        {name: "收费状态", prop: "drugName"},
        {name: "项目类型", prop: "drugSpec"},
        {name: "项目名称", prop: "unt"},
        {name: "数量", prop: "cnt"},
        {name: "执行单价", prop: "medcWayId"},
        {name: "执行金额", prop: "usedfrquId"},
        {name: "开单科室", prop: "sdoseSum"},
        {name: "开单医生", prop: "sdoseUnt"},
        {name: "执行科室", prop: "purcPric"},
        {name: "已退数量", prop: "purcPric"},
      ],
      tableRows5: [
        {name: "是否收费", prop: "feeNo", op: 'feeNoOptions'},
        {name: "业务来源", prop: "busFrom", op: 'busFromOptions'},
        {name: "医嘱内容", prop: "drordName"},
        {name: "数量", prop: "cnt"},
        {name: "已执行数量", prop: "reptdCnt"},
        {name: "执行频率", prop: "exeFrquId", op: 'medicationFrequencyOptions'},
        {name: "应执行日期", prop: "exeDate"},
        //{name: "执行数量", prop: "frquCnt"},
        //{name: "取药否", prop: "sendState", op: 'getMedicineStateOptions'},
      ],

      tableRows6: [
        {name: "收费状态", prop: "feeNo", op: 'feeNoOptions'},
        {name: "取药否", prop: "sendState", op: 'getMedicineStateOptions'},
        {name: "医嘱内容", prop: "drordName"},
        {name: "用药频率", prop: "exeFrquId", op: 'medicationFrequencyOptions'},
        {name: "执行次数", prop: "cnt"},
        {name: "已执行次数", prop: "reptdCnt"},
        {name: "应执行日期", prop: "exeDate"},
        {name: "周期天数", prop: "prdDays"},
        {name: "处方科室", prop: "bilgDeptName"},
        {name: "处方医生", prop: "bilgDrName"},
        {name: "输液速度", prop: "speed"},
        {name: "备注", prop: "drordRemarks"},
      ],
      tableRows7: [
        {name: "单据序号", prop: "nursDetId"},
        {name: "打印瓶贴", prop: "labelPrint", op: 'isPrintOptions'},
        {name: "打印输液卡", prop: "infusionPrint", op: 'isPrintOptions'},
        {name: "执行人", prop: "exeUserName"},
        {name: "执行时间", prop: "exeDatetime"},
        {name: "执行科室", prop: "exeDeptId", op: 'deptOptions'},
      ],
      tableRows8: [
        {name: "单据序号", prop: "nursDetId"},
        {name: "皮试开始时间", prop: "exeDatetime"},
        {name: "皮试结束时间", prop: "skintstDicmEnd"},
        {name: "皮试结果", prop: "skintstDicmResult", op: 'skinTestOption'},
        {name: "执行人", prop: "exeUserName"},
        {name: "执行科室", prop: "exeDeptId", op: 'deptOptions'},
      ],
      tableRows9: [
        {name: "单据序号", prop: "nursDetId"},
        {name: "执行科室", prop: "exeDeptId", op: 'deptOptions'},
        {name: "执行人", prop: "exeUserName"},
        {name: "执行时间", prop: "exeDatetime"},
        {name: "操作时间", prop: "createTime"},
      ],
      tableRows14: [
        {name: "健康ID", prop: "id"},
        {name: "健康卡号", prop: "patId"},
        {name: "姓名", prop: "name"},
        {name: "身份证号", prop: "certno"},
        {name: "联系电话", prop: "conerTel"},
      ],
      //表单
      addUnitForm: {
        id: null,
        code: '',
        state: 1,
        area: 1,
        name: '',
        pyCode: '',
        bankName: '',
        bankNo: '',
        splerPmtno: '',
        legalRepe: '',
        mainConer: '',
        conerPhone: '',
        conerTel: '',
        conerQq: '',
        conerFax: '',
        conerPostc: '',
        url: '',
        conerMail: '',
        untAtte: 3,
        uscc: '',
        conerAdd: '',
        remark: ''
      },//合约单位新增修改表单
      addOnCreditForm: {
        beginTime: '',
        code: '',
        cotUnit: null,
        endTime: '',
        name: '',
        pycode: '',
        remarks: '',
        state: 1,
      },//挂账类型新增修改表单
      patientChooseForm: {
        id: null,
        patId: '',
        name: '',
        sex: null,
        certno: null,
        conerTel: null,
        contractUnit: null,
        healthCardNo: null,
        cardType: null,
      },//选择患者表单
      queryConditionForm: {
        id: null,
        patId: '',
        chargePerson: null,
        patientType: null,
        timeFrameArr: [
          dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
          dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
        ],
        timeFrame: 0,
        executeState: 0,
        executeType: 0,
        deptId: null,
        executeTime: new Date(),
      },//表格头表单
      editDateTime: {
        startDateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        endDateTime: '',
        exeSkintstType: null,
      },

      planDateTime: {
        startDateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        endDateTime: '',
        exeSkintstType: null,
      },
      paymentForm: {
        age: null,
        aliAmt: null,
        bankAmt: null,
        bebtAmt: null,
        bebtId: null,
        bebtType: '',
        bilgDepId: null,
        bilgDepName: '',
        bilgDrId: null,
        bilgDrName: '',
        cashAmt: null,
        chsAmt: null,
        distAmt: null,
        groupAmt: null,
        invoNo: '',
        opeWay: null,
        paidAmt: null,
        patAmt: null,
        patCostType: null,
        patId: null,
        patName: '',
        patType: null,
        recdAmt: null,
        receAmt: null,
        regId: null,
        remarks: '',
        seeId: null,
        sex: null,
        shHarId: null,
        wechatAmt: null,
        balance: null,
        observation: null,
        observationAdvance: null,
        change: null,
      },//门诊收费结算表单
      patientForm: {
        id: null,
        patId: '',       // 健康ID
        name: '',           // 姓名
        sex: null,       // 性别
        brdy: '',      // 出生日期
        ageYear: null,        // 年龄-岁
        jobId: null,            // 职业
        prhType: null, // 病员类型
        contractUnit: null,  // 合约单位
        conerName: '',        // 联系人
        conerTel: '',          // 联系电话
        conerRltsId: null, // 联系人关系
        mrgState: null,//婚姻
        conerAddName: '',//联系地址
        tel: '',//本人电话
        allergen: null,//过敏原
        bodyHeight: '',//身高
        bodyWeight: '',//体重
        bodyTemperature: '',//体温
        breathe: '',//呼吸
        pulse: '',//脉搏
        diapre: null,//舒张压
        syspre: null,//收缩压
        bloodNumber: null,//血糖
        diagnostics: null,//诊断
        medicalAdviceContent: '',//医嘱内容
      },//患者信息表单
      refundForm: {
        detailId: null,
        paidAmt: null,
        cnt: null,
      },
      refundFormRules: {
        cnt: [
          {required: true, message: '退费数量不能为空', trigger: 'blur'},      // 必填
          {type: 'number', message: '必须为数字', trigger: 'blur'},            // 必须为数字
          {validator: this.validateNuyCnt, trigger: 'blur'}                   // 自定义验证（最小值）
        ]
      },

      //新增健康档案表单
      celerityFilingForm: {
        name: '',           // 姓名
        sex: null,       // 性别
        identityCard: 1,
        certno: '',   //证件号码
        brdy: '',      // 出生日期
        ageYear: 0,        // 年龄-岁
        ageMonth: 0,       // 年龄-月
        ageDay: 0,       // 年龄-天
        naty: 1,     // 民族
        ntlyId: 1,    //国籍
        jobId: '',            // 职业
        prhType: null, // 病员类型
        contractUnit: null,  // 合约单位
        conerName: '',        // 联系人
        conerTel: '',          // 联系电话
        conerRltsId: null, // 联系人关系
        province: '',       // 省
        city: '',           // 市
        county: '',         // 县
        town: '',           // 乡
        village: '',         //村
        tel: null,
        restAddCode: null,
        naplAddCode: null,
      },


      //表单验证
      addOnCreditFormRules: {
        code: [
          {required: true, message: '请输入编码', trigger: 'blur'},
          {min: 2, max: 20, message: '长度在2到20个字符', trigger: 'blur'}
        ],
        cotUnit: [
          {required: true, message: '请选择合约单位', trigger: 'change'}
        ],
        name: [
          {required: true, message: '请输入名称', trigger: 'blur'},
          {min: 2, max: 50, message: '长度在2到50个字符', trigger: 'blur'}
        ],

        beginTime: [
          {required: true, message: '请选择开始时间', trigger: 'change'}
        ],
        endTime: [
          {required: true, message: '请选择结束时间', trigger: 'change'},
          {
            validator: (rule, value, callback) => {
              if (this.addOnCreditForm.beginTime && value) {
                if (new Date(value) < new Date(this.addOnCreditForm.beginTime)) {
                  callback(new Error('结束时间不能早于开始时间'));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: 'change'
          }
        ]
      }, //挂账
      addUnitRules: {
        code: [{required: true, message: '请填写合约单位编码！', trigger: 'change'}],
        name: [{required: true, message: '请填写合约单位名称！', trigger: 'change'}],
      },//合约单位
      userInfo: null,
    };
  },
  computed: {
    actionButtons() {
      // 费用记账页面
      if (this.therapyManage === 'billing') {
        return [
          {
            text: '记账',
            type: 'success',
            action: this.handleExecutionPlan
          },
          {
            text: '急诊记账',
            type: 'warning',
            action: this.handleExecutionPlan
          }
        ]
      }

      // 治疗管理页面
      if (this.therapyManage === 'treatment') {
        return [
          /*{
            text: '打印执行单',
            type: 'primary',
            action: this.handleExecutionPlan
          },*/
          {
            text: '执行医嘱',
            type: 'success',
            action: this.handleExecutionPlan
          },
          {
            text: '取消执行',
            type: 'danger',
            action: this.handleCancelExecute
          },
          /*{
            text: '打印',
            type: 'danger',
            action: this.handleCancelExecute
          }*/
        ]
      }

      // 皮试管理页面
      if (this.therapyManage === 'skinTest') {
        return [
          {
            text: '修改时间',
            type: 'success',
            action: this.handleEditExecutionPlanTime
          },
          {
            text: '开始皮试',
            type: 'success',
            action: this.handleSelectExecutionPlanDate
          },
          {
            text: '取消皮试',
            type: 'primary',
            action: this.handleCancelSelSkinTest
          },
          {
            text: '结束皮试',
            type: 'primary',
            action: this.handleOpenSelSkinTest
          },
        ]
      }

      if (this.therapyManage === 'intravenousInfusion') {
        return [
          {
            text: '打印身份识别卡',
            type: 'primary',
            action: this.printIdentityCard
          },
          {
            text: '打印瓶贴',
            type: 'primary',
            action: this.printBottleLabel
          },
          {
            text: '打印输液卡',
            type: 'primary',
            action: this.printInfusionCard
          },
          {
            text: '执行',
            type: 'success',
            action: this.handleSelectExecutionPlanDate
          },
          {
            text: '取消执行',
            type: 'danger',
            action: this.handleCancelExecute
          },
          {
            text: '禁用执行',
            type: 'danger',
            action: this.handleDisableExeTable
          }
        ]
      }

      if (this.therapyManage === 'boilMedicine') {
        return [
          {
            text: '执行',
            type: 'success',
            action: this.handleSelectExecutionPlanDate
          },
          {
            text: '取消执行',
            type: 'danger',
            action: this.handleCancelExecute
          },
          {
            text: '禁用执行',
            type: 'danger',
            action: this.handleDisableExeTable
          }
        ]
      }
      // 默认返回空数组
      return []
    }
  },
  watch: {
    tableData1: {
      handler(newVal) {
        if (newVal.length < 1) {
          this.tableData2 = [];
          this.tableData3 = [];
          this.tableData4 = [];
          this.tableData5 = [];
          this.patientForm = Object.assign({}, this.$options.data.call(this).patientForm)
        }
      },
      deep: true
    }
  },
  mounted() {
    this.addUnitType = AddType.map(function (v) {
      return v
    })
    this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    this.loadData();
    this.getDeptList();
    this.dict();
    this.getContuntList();
    this.getDoctorList();
    this.getAiseList();
    this.getMedicationFrequency();
    this.$nextTick(() => {
      this.updateWindowWidth();
      window.addEventListener('resize', this.updateWindowWidth);
    })
  },
  methods: {
    handleStartTimeChange(startTime) {
      if (!startTime) {
        this.planDateTime.endDateTime = null;
        return;
      }
      if (this.planDateTime.endDateTime) {
        const minEndTime = new Date(startTime);
        minEndTime.setMinutes(minEndTime.getMinutes() + 5);
        if (new Date(this.planDateTime.endDateTime) < minEndTime) {
          this.$message.warning("结束时间必须比开始时间晚至少5分钟");
          this.planDateTime.endDateTime = null;
        }
      }
    },
    handleEndTimeChange(endTime) {
      if (!endTime || !this.planDateTime.startDateTime) return;
      const minEndTime = new Date(this.planDateTime.startDateTime);
      minEndTime.setMinutes(minEndTime.getMinutes() + 5);
      if (new Date(endTime) < minEndTime) {
        this.$message.warning("结束时间必须比开始时间晚至少5分钟");
        this.planDateTime.endDateTime = null;
      }
    },

    async submitDateTime() {
      if (!this.planDateTime.startDateTime || !this.planDateTime.endDateTime) {
        this.$message.warning("请选择完整时间范围");
        return;
      }
      const minEndTime = new Date(this.planDateTime.startDateTime);
      minEndTime.setMinutes(minEndTime.getMinutes() + 5);
      if (new Date(this.planDateTime.endDateTime) < minEndTime) {
        this.$message.warning("时间间隔必须≥5分钟");
        return;
      }
      const newItem = {
        id: this.currentExecuteDetailData.id,
        skintstDicmBegin: this.planDateTime.startDateTime,
        exeDatetime: this.planDateTime.startDateTime,
        skintstDicmEnd: this.planDateTime.endDateTime,
        exeSkintstType: this.planDateTime.exeSkintstType ? 1 : 0,
        skintstDicmResult: this.planDateTime.exeSkintstType,
      };
      console.log(newItem, 'newItemnewItemnewItem')
      await withLoading(this, '数据处理中...')(async () => {
        const res = await exePlanSTEdit(newItem);
        if (res.code === 200) {
          this.$message.success("更新皮试结果成功!")
          await this.handleRowClick(this.stayExecutionList)
          await new Promise(resolve => setTimeout(resolve, 1000));
          this.planDateTime = Object.assign({}, this.$options.data.call(this).planDateTime)
          this.editDateTimeDialogVisible = false;
        } else {
          this.$message.error(res.message)
        }
      });

      // 提交后关闭对话框
      this.editDateTimeDialogVisible = false;
    },
    async getDoctorList() {
      if (this.doctorOptions.length > 0) return;
      const res = await getDoctorList();
      if (res.code === 200) {
        this.doctorOptions = res.data.map(item => {
          return {id: item.id, label: item.fullName}
        })
      } else {
        this.$message.error(res.message)
      }
    },
    async handleChoosePatient() {
      this.queryConditionForm.patId = this.patientChooseForm.id;
      await this.loadData();
      this.queryConditionForm.patId = this.patientChooseForm.patId;
      this.patientDialogVisible = false;
    },
    async handleClickRow(row) {
      this.patientChooseForm = JSON.parse(JSON.stringify(row));
    },
    handleCloseChoosePatient() {
      this.patientDialogVisible = false;
    },
    async handleSearch() {
      const res = await getDocphrByCondtion({condtion: this.queryConditionForm.patId});
      if (res.data.length > 1) {
        this.patientTabelData = res.data;
        this.patientDialogVisible = true;
        return;
      } else if (res.data.length <= 0) {
        this.$message.warning("没有搜索到相关患者!请在健康档案新增或挂号菜单快速建档!")
        return;
      }
      this.patientChooseForm = res.data[0];
      this.queryConditionForm.patId = res.data[0].id;
      await this.loadData();
      this.queryConditionForm.patId = res.data[0].patId;
      this.patientDialogVisible = false;
    },

    async printIdentityCard() {
      if (Object.keys(this.stayExecutionList).length === 0) {
        this.$message.warning("请选中需要打印患者")
        return;
      }
      const res = await this.planIdentityCard();
      printUtil.init(identityCard);
      printUtil.print(res)
    },
    async printBottleLabel() {
      if (!this.currentExecuteData?.id) {
        this.$message.warning("请选中需要打印的执行选项")
        return;
      }
      const res = await this.planBottleLabel();
      printUtil.init(bottleLabel);
      printUtil.print(res)
    },
    async printInfusionCard() {
      if (!this.currentExecuteData?.id) {
        this.$message.warning("请选中需要打印的执行选项")
        return;
      }
      const res = await this.planInfusionCard();
      printUtil.init(infusionCard);
      printUtil.print(res)
    },

    async planInfusionCard() {
      const res = await getSeedoctorById({id: this.stayExecutionList.seeId});
      console.log(res, 'infusionCard.jsinfusionCard.js')
      return {
        ...this.stayExecutionList,
        doctor: this.userInfo.staffName,
        sex: this.sexOptions.find(item => item.id === this.stayExecutionList.sex)?.label,
        dept: this.deptOptions.find(item => item.id === this.userInfo.selDept)?.label,
        aise: this.aiseListOptions.find(item => item.id === parseInt(res.data.allergen))?.label,
        patId: res.data.patNo,
        seedoctorId: res.data.id,
        date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        westernDiagnos: res.data.westernDiagnos,
        west: this.tableData2
            .map(item => `(${item.drordName})`)
            .join('')
      }
    },

    async planBottleLabel() {
      const res = await getSeedoctorById({id: this.stayExecutionList.seeId});
      return {
        ...this.stayExecutionList,
        doctor: this.userInfo.staffName,
        sex: this.sexOptions.find(item => item.id === this.stayExecutionList.sex)?.label,
        dept: this.deptOptions.find(item => item.id === this.userInfo.selDept)?.label,
        aise: this.aiseListOptions.find(item => item.id === parseInt(res.data.allergen))?.label,
        patId: res.data.patNo,
        date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
      }
    },
    async planIdentityCard() {

      const res = await getSeedoctorById({id: this.stayExecutionList.seeId});
      console.log(res, 'this.stayExecutionListthis.stayExecutionListthis.stayExecutionList')
      return {
        ...this.stayExecutionList,
        doctor: this.doctorOptions.find(item => item.id === res.data.doctorId)?.label,
        sex: this.sexOptions.find(item => item.id === this.stayExecutionList.sex)?.label,
        dept: this.deptOptions.find(item => item.id === this.userInfo.selDept)?.label,
        aise: this.aiseListOptions.find(item => item.id === parseInt(res.data.allergen))?.label,
        patId: res.data.patNo,
      }
    },
    /*根据时间获取输液注射执行*/
    async handleGetExeDetailByDate() {
      const res = await getExeDetail({
        exeDate: dayjs(this.queryConditionForm.executeTime).format('YYYY-MM-DD'),
        exeType: this.stayExecutionList.exeType,
        id: this.stayExecutionList.id,
      });
      if (res.code === 200) {
        this.tableData2 = res.data.map(item => {
          return {
            ...item,
            exeDate: dayjs(item.exeDate).format('YYYY-MM-DD')
          }
        });
        this.tableData3 = [];
      }
    },
    /*禁用*/
    async handleDisableExeTable(row) {
      try {
        await this.$confirm('确认禁用执行吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        await withLoading(this, '数据处理中...')(async () => {
          const res = await disableExeTable({id: row.id});
          if (res.code === 200) {
            await this.loadData();
            this.$message.success("禁用执行成功!")
          } else {
            this.$message.error(res.message)
          }
        });
      } catch (error) {
      }
    },

    /*取消执行*/
    async handleCancelExecute() {
      if (this.currentExecuteDetailData === null) {
        this.$message.warning("请选中下方明细行再进行操作")
        return;
      }
      try {
        await this.$confirm('确认取消执行吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        await withLoading(this, '数据处理中...')(async () => {
          const res = await cancelExePlan({exePlanDetailId: this.currentExecuteDetailData.id});
          if (res.code === 200) {
            this.$message.success("取消执行成功!")
            await this.handleRowClick(this.stayExecutionList)
            await new Promise(resolve => setTimeout(resolve, 1000));
            await this.getExePlanList(this.currentExecuteData.detailId);
          } else {
            this.$message.error(res.message)
          }
        });
      } catch (error) {

      }
    },

    /*左侧下方表格*/
    handleCurrentExecuteDetailRow(row) {
      this.currentExecuteDetailData = JSON.parse(JSON.stringify(row))
    },

    /*取消皮试*/
    async handleCancelSelSkinTest() {
      if (this.currentExecuteDetailData === null) {
        this.$message.warning("请选中下方明细行再进行操作")
        return;
      }
      /*if (this.currentExecuteDetailData.skintstDicmResult !== null) {
        this.$message.warning("该皮试已出结果")
        return;
      }*/
      await withLoading(this, '数据处理中...')(async () => {
        const res = await cancelExePlan({exePlanDetailId: this.currentExecuteDetailData.id})
        if (res.code === 200) {
          await this.handleRowClick(this.stayExecutionList)
          await new Promise(resolve => setTimeout(resolve, 1000));
          await this.getExePlanList(this.currentExecuteData.detailId);
        } else {
          this.$message.error(res.message)
        }
      });
    },

    /*开始皮试*/
    async handleOpenSelSkinTest() {
      if (this.currentExecuteDetailData === null) {
        this.$message.warning("请选中下方明细行再进行操作")
        return;
      }
      if (this.currentExecuteDetailData.skintstDicmResult !== null) {
        this.$message.warning("该皮试已出结果")
        return;
      }
      await withLoading(this, '数据处理中...')(async () => {
        const beginTime = new Date(this.currentExecuteDetailData.skintstDicmBegin);
        const endTime = new Date(this.currentExecuteDetailData.skintstDicmEnd);
        /*const timeDiffMs = endTime - beginTime;
        const requiredMinDiff = 5 * 60 * 1000; // 5分钟的毫秒数
        if (timeDiffMs < requiredMinDiff) {
          this.$message.warning("皮试结束时间必须晚于开始时间至少5分钟");
          return;
        }*/
        this.selSkinTestResultDialogVisible = true;
      });
    },

    /*皮试模态框取消*/
    handleCloseSelSkinTest() {
      this.selSkinTestResultDialogVisible = false;
      this.exeSkintstType = null;
    },

    /*修改时间模态框取消*/
    handleCloseEditDate() {
      this.editDateTime = Object.assign({}, this.$options.data.call(this).editDateTime)
      this.editDateTimeDialogVisible = false;
    },

    /*执行时间模态框取消*/
    handleClosePlanDate() {
      this.planDateTime = Object.assign({}, this.$options.data.call(this).planDateTime)
      this.planDateTimeDialogVisible = false;
    },

    /*更新皮试结果*/
    async exePlanSTEdit() {
      if (this.planDateTime.endDateTime === '') return this.$message.warning("请选择结束时间");
      if (this.exeSkintstType === null) return this.$message.warning("请选择皮试结果");
      const newItem = {
        id: this.currentExecuteDetailData.id,
        exeSkintstType: 1,
        skintstDicmResult: this.exeSkintstType,
        skintstDicmEnd: this.planDateTime.endDateTime,
      };
      console.log(newItem, 'newItemnewItemnewItemnewItem')
      await withLoading(this, '数据处理中...')(async () => {
        const res = await exePlanSTEdit(newItem);
        if (res.code === 200) {
          this.$message.success("更新皮试结果成功!")
          await this.handleRowClick(this.stayExecutionList)
          await new Promise(resolve => setTimeout(resolve, 1000));
          this.handleCloseSelSkinTest();
        } else {
          this.$message.error(res.message)
        }
      });
      await this.getExePlanList(this.currentExecuteData.detailId);
    },

    handleSelectionChange(selection, row) {
      if (selection.includes(row)) {
        this.$refs.singleSelectTable.clearSelection();
        this.$nextTick(async () => {
          this.$refs.singleSelectTable.toggleRowSelection(row, true);
          this.currentExecuteData = JSON.parse(JSON.stringify(row));
          await this.getExePlanList(row.detailId);
        });
      }
    },

    /*修改时间*/
    async handleEditExecutionPlanTime() {
      if (this.currentExecuteDetailData === null) {
        this.$message.warning("请选中下方明细行再进行操作")
        return;
      }
      /*if (this.currentExecuteDetailData.skintstDicmResult !== null) {
        this.$message.warning("该皮试已出结果")
        return;
      }*/
      this.editDateTime = Object.assign({}, this.$options.data.call(this).editDateTime)
      this.planDateTime.startDateTime = this.currentExecuteDetailData.skintstDicmBegin === ''
          ? this.planDateTime.startDateTime
          : this.currentExecuteDetailData.skintstDicmBegin;

      this.planDateTime.endDateTime = this.currentExecuteDetailData.skintstDicmEnd === ''
          ? (this.planDateTime.endDateTime === ''
              ? dayjs(this.planDateTime.startDateTime).add(5, 'minute').format()
              : this.planDateTime.endDateTime)
          : this.currentExecuteDetailData.skintstDicmEnd;
      this.editDateTimeDialogVisible = true;
    },

    /*执行时间选择*/
    async handleSelectExecutionPlanDate() {
      if (this.currentExecuteData === null) {
        this.$message.warning("请选中执行计划再进行操作!");
        return;
      }
      if (this.currentExecuteDetailData?.skintstDicmResult != null) {
        this.$message.warning("该皮试已出结果");
        return;
      }
      this.planDateTime = Object.assign({}, this.$options.data.call(this).planDateTime);
      this.planDateTimeDialogVisible = true;
    },

    /*执行*/
    async handleExecutionPlan() {
      if (this.stayExecutionList.exeType === 3) {
        await withLoading(this, '数据处理中...')(async () => {
          const newItem = {
            exeDatetime: this.planDateTime.startDateTime,
            skintstDicmBegin: this.planDateTime.startDateTime,
            skintstDicmEnd: this.planDateTime.endDateTime,
            nursDetId: this.currentExecuteData.detailId,
            exePrint: 0,
            infusionPrint: 0,
            labelPrint: 0,
            exeDeptId: this.userInfo.selDept,
          };
          const res = await executionPlan(newItem);
          if (res.code === 200) {
            this.$message.success("开始皮试操作成功!");
            this.planDateTimeDialogVisible = false;
            await this.handleRowClick(this.stayExecutionList)
            await new Promise(resolve => setTimeout(resolve, 1000));
            await this.getExePlanList(this.currentExecuteData.detailId);
            this.currentExecuteData = null;
            this.currentExecuteDetailData = null;
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        await withLoading(this, '数据处理中...')(async () => {
          const newItem = {
            exeDatetime: this.planDateTime.startDateTime,
            nursDetId: this.currentExecuteData.detailId,
            exePrint: 0,
            infusionPrint: 0,
            labelPrint: 0,
            exeDeptId: this.userInfo.selDept,
          };
          const res = await executionPlan(newItem);
          if (res.code === 200) {
            this.$message.success("开始执行操作成功!");
            this.planDateTimeDialogVisible = false;
            await this.handleRowClick(this.stayExecutionList)
            await new Promise(resolve => setTimeout(resolve, 1000));
            await this.getExePlanList(this.currentExecuteData.detailId);
          } else {
            this.$message.error(res.message);
          }
        });
      }
    },

    /*动态切换标签页*/
    async handleRowClick(row) {
      console.log(row, 'rowrowrowrowrowrowrowrowrowrow')
      await withLoading(this, '数据处理中...')(async () => {
        this.stayExecutionList = JSON.parse(JSON.stringify(row));
        console.log(this.stayExecutionList)
        this.therapyManage = row.exeType === 1 ? 'intravenousInfusion'
            : row.exeType === 2 ? 'intravenousInfusion'
                : row.exeType === 3 ? 'skinTest'
                    : row.exeType === 4 ? 'treatment'
                        : row.exeType === 5 ? 'boilMedicine' : ''
        clearTimeout(this.clickDebounceTimer);
        this.currentExecuteDetailData = null;
        this.currentExecuteData = null;
        this.clickDebounceTimer = setTimeout(async () => {
          await this.getPatientData(row);
        }, 300);
      });
    },

    /*加载患者信息*/
    async getPatientData(row) {
      await withLoading(this, '数据处理中...')(async () => {
        this.tableData2 = [];
        this.tableData3 = [];
        this.patientForm = {...this.$options.data().patientForm};
        const [res1, res2, res3, res4] = await Promise.all([
          getDocphrList(row.patId),
          getSeedoctorById({id: row.seeId}),
          getReceptionDiagnosis({category: 1, seeDoctorId: row.seeId}),
          getDoctoradvice({seeDoctorId: row.seeId})
        ]);
        [res1.data, res2.data, res3.data, res4.data].forEach(data => {
          if (data) Object.assign(this.patientForm, data);
        });
        this.patientForm.allergen = parseInt(this.patientForm.allergen) || 0;
        this.patientForm.diagnostics = Array.isArray(res3)
            ? res3.length > 1
                ? res3.map(d => d.diagnosticName).filter(Boolean).join(', ')
                : res3[0]?.diagnosticName || ''
            : '';
        this.patientForm.medicalAdviceContent = Array.isArray(res4.data)
            ? res4.data.length > 1
                ? res4.data.map(a => a.content).filter(Boolean).join(', ')
                : res4.data[0]?.content || ''
            : '';
        this.certnoMonitor(this.patientForm);

        this.queryConditionForm.executeTime = dayjs(row.seeDtae).format('YYYY-MM-DD');
        const res5 = await getExeDetail({
          exeDate: dayjs(this.queryConditionForm.executeTime).format('YYYY-MM-DD'),
          exeType: row.exeType,
          id: row.id,
        });
        this.tableData2 = res5.data?.map(item => ({
          ...item,
          exeDate: dayjs(item.exeDate).format('YYYY-MM-DD')
        })) || [];

        if (res5.data?.length > 0) {
          await this.handleCurrentRow(res5.data[0]); // 传入第一条数据
        }
      });
    },

    /*正则验证*/
    validateNuyCnt(rule, value, callback) {
      if (value === null || value === '') {
        callback(new Error('退费数量不能为空'));
        return;
      }
      if (isNaN(value)) {
        callback(new Error('必须为有效数字'));
        return;
      }
      if (value < 1) {
        callback(new Error('退费数量必须 ≥1'));
        return;
      }
      if (this.currentDetailTableData?.cnt !== undefined && value > this.currentDetailTableData.cnt) {
        callback(new Error(`退费数量不能超过明细数量${this.currentDetailTableData.cnt}`));
        return;
      }
      // 验证通过
      callback();
    },

    /*动态加载数据*/
    async loadRightTableData(row) {
      try {
        let apiResponse;

        this.$nextTick(() => {
          this.$refs.rightTable?.doLayout();
        });
        switch (row.feeType) {
          case 0:
            apiResponse = await getDoctordispose({seeDoctorId: row.seeId});
            if (apiResponse.code !== 200) throw apiResponse;
            this.tableData5 = apiResponse.data;
            break;

          case 1:
            apiResponse = await getWestPrescription(row.busId);
            if (apiResponse.code !== 200) throw apiResponse;
            this.tableData3 = apiResponse.data.drxDetails;
            await Promise.all([
              this.getMedicationWay(),
              this.getMedicationFrequency(),
              this.getDosaUnt()
            ]);
            break;

          case 2:
            apiResponse = await getChinaPrescription({id: row.busId});
            if (apiResponse.code !== 200) throw apiResponse;
            this.tableData4 = apiResponse.data.tcmDetailsRespVOS;
            break;
        }

      } catch (error) {
        this.$message.error(error);
        this.tableData3 = [];
        this.tableData4 = [];
        this.tableData5 = [];
      }
    },

    /*双击查看当前行明细*/
    async handleDbShowChargeDetail(row) {
      try {
        await this.handleCurrentRow(row);
        this.showChargeDtailDialog = true;
        this.$refs.rightTable.$forceUpdate();
        [0, 1, 2].includes(this.tableData2[0].feeType) ? this.showPrescriptionDetails = true : this.showPrescriptionDetails = false;
        if ([0, 1, 2].includes(this.tableData2[0].feeType)) {
          await this.getMedicationWay();
          await this.getMedicationFrequency();
          await this.getDosaUnt();
          this.currentFeeType = this.tableData2[0].feeType;
          await this.loadRightTableData(this.tableData2[0]);
        }
      } catch (error) {
        console.log(error, 'errorerrorerror')
        this.$message.error("系统异常:请联系管理员!!!")
      } finally {

      }

    },

    /*时段选择事件*/
    async handleConditionQuery() {
      this.queryConditionForm.patId = this.patientChooseForm.patId;
      await this.loadData();
    },

    /*时段选择事件*/
    handleTimeChange(selectedId) {
      switch (selectedId) {
        case 0: // 今天
          this.queryConditionForm.timeFrameArr = [
            dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss').toString(),
            dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss').toString()
          ];
          this.handleConditionQuery();
          break;

        case 1: // 昨天
          this.queryConditionForm.timeFrameArr = [
            dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
            dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 2: // 上月
          this.queryConditionForm.timeFrameArr = [
            dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD HH:mm:ss'),
            dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 3: // 本月
          this.queryConditionForm.timeFrameArr = [
            dayjs().startOf('month').format('YYYY-MM-DD HH:mm:ss'),
            dayjs().endOf('month').format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 4: // 会计期间（需自定义）
          this.queryConditionForm.timeFrameArr = [
            dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
            dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 5: // 本年
          this.queryConditionForm.timeFrameArr = [
            dayjs().startOf('year').format('YYYY-MM-DD HH:mm:ss'),
            dayjs().endOf('year').format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 6: // 上午（8:00 - 12:00）
          this.queryConditionForm.timeFrameArr = [
            dayjs().set('hour', 8).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss'),
            dayjs().set('hour', 12).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 7: // 下午（13:00 - 17:00）
          this.queryConditionForm.timeFrameArr = [
            dayjs().set('hour', 13).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss'),
            dayjs().set('hour', 17).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        case 8: // 晚上（18:00 - 22:00）
          this.queryConditionForm.timeFrameArr = [
            dayjs().set('hour', 18).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss'),
            dayjs().set('hour', 22).set('minute', 0).set('second', 0).format('YYYY-MM-DD HH:mm:ss')
          ];
          this.handleConditionQuery();
          break;

        default: // 默认今天
          this.queryConditionForm.timeFrameArr = [
            dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss').toString(),
            dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss').toString()
          ];
          this.handleConditionQuery();
      }
    },

    /*数据源*/
    async loadData() {
      const res = await getExetableList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        startTime: this.queryConditionForm.timeFrameArr[0],
        endTime: this.queryConditionForm.timeFrameArr[1],
        type: this.queryConditionForm.executeState === 0 ? null : this.queryConditionForm.executeState,
        exeType: this.queryConditionForm.executeType === 0 ? null : this.queryConditionForm.executeType,
        patId: this.patientChooseForm.id ? this.patientChooseForm.id : this.queryConditionForm.patId,
        exeDeptId: this.queryConditionForm.deptId === null ? null : this.queryConditionForm.deptId,
        state: 0
      });
      if (res.code === 200) {
        this.tableData1 = res.data.content = res.data.content
            .map(item => {
              return {
                ...item,
                brdy: item.brdy === null ? null : dayjs(item.brdy).format('YYYY-MM-DD'),
              }
            })
        if (res.data.content.length <= 0) {
          this.$message.warning("暂无患者执行信息")
        }
        this.totalSize = res.data.totalSize;
      } else {
        this.$message.error(res.message)
      }

    },

    /*单位剂量 最小剂量下拉框*/
    async getDosaUnt() {
      const res = await getDosaUnt();
      this.dosaUntOptions = res.data.map(item => {
        return {
          id: item.id, label: item.name
        }
      })
    },

    /*给药方式下拉框*/
    async getMedicationFrequency() {
      if (this.medicationFrequencyOptions.length > 0) return;
      const res = await getMedicationWay();
      if (res.code === 200) {
        this.medicationFrequencyOptions = res.data.map(item => {
          return {
            id: item.id, label: item.name, frquCnt: item.frquCnt
          }
        })
      } else {
        this.$message.error(res.message)
      }
    },

    /*用药频率下拉框*/
    async getMedicationWay() {
      if (this.medicationWayOptions.length > 0) return;
      const res = await getMedicationWay();
      this.medicationWayOptions = res.data.map(item => {
        return {
          id: item.id, label: item.name, frquCnt: item.frquCnt
        }
      })
    },

    /*表格合计列计算*/
    getSummaries(param) {
      const {columns, data} = param;
      const sums = [];

      // 需要计算的字段配置
      const calcFields = {
        'receAmt': '应收金额',
        'paidAmt': '实收金额',
        'cashAmt': '现金支付',
        'chsAmt': '医保支付',
        'patAmt': '健康卡支付',
        'distAmt': '优惠金额',
        'bebtAmt': '挂账支付',
      };

      columns.forEach((column, index) => {
        // 第一列显示行号（留空）
        if (index === 0) {
          sums[index] = '';
          return;
        }

        // 第二列（剂量单位）显示"合计"文字
        if (index === 1) {
          sums[index] = '合计';
          return;
        }

        // 只处理需要计算的字段
        if (calcFields[column.property]) {
          const total = data.reduce((sum, item) => {
            const value = parseFloat(item[column.property]) || 0;
            return sum + value;
          }, 0);

          // 如果是cnt列，显示为整数，否则保留两位小数
          sums[index] = column.property === 'cnt'
              ? Math.round(total).toString()
              : total.toFixed(2);
        } else {
          // 其他列显示占位符（与图片中的"一"一致）
          sums[index] = '';
        }
      });

      return sums;
    },

    /*获取输液注射执行详情*/
    async getExePlanList(detailId) {
      await withLoading(this, '数据处理中...')(async () => {
        const res = await getExePlanList({nursDetId: detailId, state: 0});
        if (res.code === 200) {
          this.tableData3 = res.data.map(item => ({
            ...item,
            exePrintTime: item.exePrintTime ? dayjs(item.exePrintTime).format('YYYY-MM-DD HH:mm:ss') : null,
            exeDatetime: item.exeDatetime ? dayjs(item.exeDatetime).format('YYYY-MM-DD HH:mm:ss') : null,
            createTime: item.createTime ? dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') : null,
            labelTime: item.labelTime ? dayjs(item.labelTime).format('YYYY-MM-DD HH:mm:ss') : null,
            infusionTime: item.infusionTime ? dayjs(item.infusionTime).format('YYYY-MM-DD HH:mm:ss') : null,
            skintstDicmBegin: item.skintstDicmBegin ? dayjs(item.skintstDicmBegin).format('YYYY-MM-DD HH:mm:ss') : null,
            skintstDicmEnd: item.skintstDicmEnd ? dayjs(item.skintstDicmEnd).format('YYYY-MM-DD HH:mm:ss') : null
          }));
        } else {
          this.$message.error(res.message);
        }
      });
    },

    /*拿到明细行数据*/
    async handleCurrentRow(row) {
      console.log(row, 'Cannot read properties of undefined (reading \'toggleRowSelection\')')
      this.currentExecuteData = Object.assign({}, this.$options.data.call(this).currentExecuteData)
      this.currentExecuteData = JSON.parse(JSON.stringify(row));
      const table = this.$refs.singleSelectTable;
      table.toggleRowSelection(row);
      table.setCurrentRow(row);
      await this.getExePlanList(row.detailId);
    },

    /*根据身份证生日*/
    certnoMonitor(val) {
      if (!val.certno) return;

      const idCard18Reg = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
      if (!idCard18Reg.test(val.certno)) {
        this.$message.error("身份证格式不正确");
      }

      const data = this.getAgeAndMonthsFromIdCard(val.certno);
      val.ageYear = data.years;
      val.ageMonth = data.months;
      val.brdy = val.certno.slice(6, 10) + '-' +
          val.certno.slice(10, 12) + '-' +
          val.certno.slice(12, 14)
    },

    /*根据身份证出生日期*/
    getAgeAndMonthsFromIdCard(idCard) {
      if (!idCard || idCard.length !== 18) return {years: 0, months: 0, birthday: ''};

      const birthStr = idCard.slice(6, 14); // 格式：YYYYMMDD
      const birthday = `${birthStr.slice(0, 4)}-${birthStr.slice(4, 6)}-${birthStr.slice(6, 8)}`;

      const birthDate = new Date(birthday);
      if (isNaN(birthDate.getTime())) return {
        years: 0,
        months: 0,
        birthday: ''
      };

      // 2. 获取当前日期
      const today = new Date();

      // 3. 计算周岁
      let years = today.getFullYear() - birthDate.getFullYear();

      // 4. 计算月龄（总月数差）
      let months = (today.getFullYear() - birthDate.getFullYear()) * 12 +
          (today.getMonth() - birthDate.getMonth());

      // 5. 调整年龄和月龄（如果生日未到）
      if (
          today.getMonth() < birthDate.getMonth() ||
          (today.getMonth() === birthDate.getMonth() && today.getDate() < birthDate.getDate())
      ) {
        years--;
        months--;
      }

      // 6. 确保月龄为正数
      months = Math.max(0, months % 12); // 超过12个月的部分已计入周岁

      return {years, months, birthday};
    },

    /*科室下拉框*/
    async getDeptList() {
      if (this.deptOptions.length > 0) return;
      const res = await getDeptList();
      if (res.code === 200) {
        this.deptOptions = res.data.map(item => {
          return {id: item.id, label: item.deptName}
        })
      } else {
        this.$message.error(res.message)
      }
    },

    async getAiseList() {
      if (this.aiseListOptions.length > 0) return;
      const res = await getAiseList();
      if (res.code === 200) {
        this.aiseListOptions = res.data.map(item => {
          return {label: item.name, id: item.id}
        })
      } else {
        this.$message.error(res.message)
      }
    },
    /*数据字典*/
    async dict() {
      const res = await dict();
      this.nationOption = res.data.natyEntities.map(item => {
        return {id: item.id, label: item.name}
      })
      this.certypeOption = res.data.certypeEntities.map(item => {
        return {id: item.id, label: item.name}
      })

      this.profttlOption = res.data.profttlEntities.map(item => {
        return {id: item.id, label: item.name}
      })

      this.jobOption = res.data.jobEntities.map(item => {
        return {id: item.id, label: item.name}
      })

      this.prhCostOption = res.data.prhCostType.map(item => {
        return {id: item.id, label: item.name}
      })

      this.prhTypeOption = res.data.prhType.map(item => {
        return {id: item.id, label: item.name}
      })

      this.rltsEntitiesOption = res.data.rltsEntities.map(item => {
        return {id: item.id, label: item.name}
      })

      this.untAtteOption = res.data.unatteVo.map(item => {
        return {id: item.id, label: item.name}
      })

      this.ntlyOptions = res.data.country.map(item => {
        return {id: item.id, label: item.name}
      })

      this.chinaMakeOptions = res.data.methodTypeVO.map(item => {
        return {id: item.id, label: item.name}
      })

      this.tcmwayOptions = res.data.tcmway.map(item => {
        return {id: item.id, label: item.name}
      })

      this.mrgStateEntitiesOptions = res.data.mrgStateEntities.map(item => {
        return {id: item.id, label: item.name}
      })
    },

    /*合约单位下拉框*/
    async getContuntList() {
      if (this.contractUnitOption.length > 0) return;
      const res = await getContuntList();
      if (res.code === 200) {
        this.contractUnitOption = res.data.map(item => {
          return {id: item.id, label: item.name}
        })
      } else {
        this.$message.error(res.message)
      }
    },

    updateWindowWidth() {
      this.windowWidth = window.innerWidth - 288;
    },
    safeGetMappedValue(col, row) {
      // 1. 检查数据有效性
      const rawValue = row[col.prop];
      if (rawValue === null || rawValue === undefined) return ' ';

      // 2. 检查映射数组
      const mapArray = this[col.op];
      if (!col.op || !Array.isArray(mapArray)) return rawValue;

      // 3. 执行映射
      const matched = mapArray.find(item => item.id == rawValue);
      return matched?.label || rawValue;
    },
    getColumnWidth(label, prop, tableData) {
      const minWidth = 80;
      const padding = 30; // 增加边距缓冲
      const contentList = tableData.map(item => item?.[prop] ?? '');

      // 计算所有内容宽度（包括表头）
      const widths = [...contentList, label].map(text => {
        const str = String(text || '');
        return this.getTextWidth(str) + padding;
      });

      return Math.max(minWidth, ...widths);
    },
    getTextWidth(text, fontSize = 14) {
      const canvas = document.createElement('canvas');
      const ctx = canvas.getContext('2d');
      ctx.font = `${fontSize}px Microsoft YaHei`;
      return ctx.measureText(text).width;
    },
    labelHead(h, {column, $index}) {
      let l = column.label.length;
      let f = 12;
      column.minWidth = f * (l + 5); //加上一个文字长度
      return h("div", {class: "table-head", style: {width: "100%"}}, [
        column.label,
      ]);
    },
    handleSizeChange(val) {
      this.pageNum = val;
      this.loadData();
    },
    //当前条数改变触发
    handleCurrentChange(val) {
      this.pageNum = val;
      this.loadData();
    },
  }
}
</script>


<style lang="less" scoped>
/* 响应式表单样式 */
.responsive-form {
  overflow: hidden;
}

/* 表单行样式 */
.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: -8px; /* 补偿 gutter 的 margin */
}

/* 通用输入控件样式 */
.full-width-input,
.full-width-select,
.full-width-date-picker {
  width: 100% !important;
}

/* 时间范围容器 */
.date-range-container {
  display: flex;
  align-items: center;
  width: 100%;
}

/* 日期选择器 */
.date-picker {
  flex: 1;
  min-width: 150px;
}

/* 日期分隔符 */
.date-separator {
  margin: 0 8px;
  color: #999;
}

/* 小屏幕下的调整 */
@media (max-width: 768px) {
  .date-range-container {
    flex-direction: column;
  }

  .date-picker {
    width: 100%;
    margin-bottom: 8px;
  }

  .date-separator {
    display: none;
  }
}

/* 紧凑表单项 */
.compact-form-item {
  margin-bottom: 8px;
}

/* 按钮区域样式 */
.dialog-footer {
  text-align: right;
  margin-top: 25px;
  padding-right: 15px;
}

.bottom-control-form {
  margin-top: 10px;
  padding: 10px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.button-group {
  width: 100%;
}

.action-buttons {
  /* 使用flex布局将按钮推到右侧 */
  display: flex;
  justify-content: flex-end;
  gap: 10px; /* 按钮之间的间距 */
}


.ultra-compact-form {
  margin-bottom: 0;
}

.form-row.nowrap-row {
  display: flex;
  flex-wrap: nowrap;
  white-space: nowrap;
  margin-bottom: -8px;
}


/* 窄化控件 */
.narrow-input, .narrow-select, .narrow-date-picker {
  width: 100%;
}

/* 防止标签换行 */
.ultra-compact-form /deep/ .el-form-item__label {
  white-space: nowrap;
  padding-right: 5px;
}

/* 调整Element组件内部样式 */
.ultra-compact-form /deep/ .el-input__inner {
  height: 26px;
  line-height: 26px;
  padding: 0 8px;
}

/* 五列表单样式 */
.five-col-form .el-col {
  padding: 0 6px;
}

.five-col-form .el-form-item {
  margin-bottom: 12px;
}

/* 防止标签换行 */
.nowrap-label .el-form-item__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
}

/* 紧凑表单样式 */
.compact-form {
  font-size: 12px;
}

.compact-form .form-row {
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
}

.compact-form .compact-item {
  margin-bottom: 0;
}

.compact-form .el-form-item__label {
  padding-right: 8px;
  color: #606266;
}

.compact-form .el-input__inner,
.compact-form .el-select,
.compact-form .el-date-editor {
  width: 100%;
}

/* 带单位的输入框样式 */
.with-unit {
  display: flex;
  align-items: center;
}

.with-unit .el-input {
  flex: 1;
}

.with-unit .unit {
  margin-left: 6px;
  color: #909399;
  font-size: 12px;
  white-space: nowrap;
}

/* 血压特殊样式 */
.blood-pressure {
  display: flex;
  align-items: center;
}

.blood-pressure .divider {
  margin: 0 4px;
  color: #909399;
}

::v-deep .el-tabs__content {
  flex: 1;
  padding: 0 !important;
  overflow: auto; /* 改为auto而不是hidden */
  height: 100%;
}

.medical-system-container {
  display: flex;
  flex-direction: column;
  height: 68vh;
  width: 100%;
  overflow: hidden;
}

.table-main-container {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.left-tabs-container {
  width: 45%;
  min-width: 300px; /* 最小宽度 */
  max-width: 70%; /* 最大宽度 */
  height: 100%;
  display: flex;
  flex-direction: column;
  resize: horizontal; /* 允许水平拖动 */
  overflow: hidden;
  border-right: 1px solid #ddd;
}

.left-tabs {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 右侧标签页容器 - 自动填充剩余空间 */
.right-tabs-container {
  flex: 1; /* 自动填充剩余空间 */
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 400px; /* 最小宽度 */
}

/* 确保内部元素不会溢出 */
.left-tabs, .right-tabs {
  height: 100%;
  overflow: hidden;
}

/* 表格容器 */
.table-container {
  height: 100%;
  overflow: auto;
}

.right-tabs {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 表格容器 - 确保表格填满可用空间 */
.table-container {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* 治疗管理容器 */
.treatment-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  /* 新增：防止flex子元素延迟渲染 */
  overflow: hidden;
}

/* 治疗管理容器 */
.treatment-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden; /* 禁用外部滚动 */
}

/* 表格区域基础样式 */
.treatment-main-table,
.treatment-detail-table {
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 禁用内部元素溢出 */
}

/* 主治疗表格 (70%) */
.treatment-main-table {
  flex: 6;
  margin-bottom: 10px; /* 替代原来的margin-top */
}

/* 治疗明细表格 (30%) */
.treatment-detail-table {
  flex: 4;
}

/* 表格包装容器 - 唯一滚动条所在层 */
.table-wrapper {
  flex: 1;
  overflow: auto; /* 唯一滚动条 */
  border: 1px solid #ebeef5;
  border-radius: 4px;
}

/* 表格样式调整 - 禁用内部滚动 */
.treatment-container .el-table {
  flex: 1;
  min-width: fit-content;
  /* 禁用表格自带的滚动 */

  ::v-deep .el-table__body-wrapper {
    overflow: hidden !important;
  }
}

/* 表头固定 */
.treatment-container ::v-deep .el-table__header-wrapper {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* 单元格内容不换行 */
.treatment-container ::v-deep .cell {
  white-space: nowrap;
  padding: 0 10px;
}

/* 强制表头和表体同宽 */
.treatment-container ::v-deep .el-table__header,
.treatment-container ::v-deep .el-table__body {
  min-width: 100%;
}

.primary-actions {
  display: flex;
}


/* 表单样式 */
.info-form {
  padding: 15px;
}

.white-bg {
  background: #fff;
}

/* 调整ElementUI组件内部样式 */
::v-deep .el-tabs__content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

::v-deep .el-tab-pane {
  height: 100%;
  display: flex;
  flex-direction: column;
}

::v-deep .el-table {
  flex: 1;
}


.el-table__body-wrapper {
  flex: 1;
  overflow: auto;
}

/* 冲销状态标签样式 */
.nuy-state-tag {
  margin: 2px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

.nuy-state-0 {
  color: #67c23a;
  background-color: #f0f9eb;
  border-color: #e1f3d8;
}

.nuy-state-1 {
  color: #e6a23c;
  background-color: #fdf6ec;
  border-color: #faecd8;
}

.nuy-state-2 {
  color: #f56c6c;
  background-color: #fef0f0;
  border-color: #fde2e2;
}

/* 图标样式 */
.el-icon-check {
  margin-right: 5px;
  color: #67c23a;
}

.el-icon-refresh {
  margin-right: 5px;
  color: #e6a23c;
}

.el-icon-close {
  margin-right: 5px;
  color: #f56c6c;
}


.form-row {
  margin-bottom: 15px;
  display: flex;
  align-items: center;
}

.time-range {
  display: flex;
  align-items: center;
}

.time-range .el-time-picker {
  flex: 1;
}

.separator {
  margin: 0 8px;
  color: #606266;
}

.el-form-item {
  margin-bottom: 0;
}


.payment-form {
  background: #f5f5f5;
  padding: 20px;
  border-radius: 4px;
}

.form-header {
  background: #409EFF;
  color: white;
  padding: 10px 15px;
  margin: -20px -20px 20px -20px;
  border-radius: 4px 4px 0 0;
  font-size: 16px;
  font-weight: bold;
}

.form-section {
  background: white;
  padding: 15px;
  margin-bottom: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.payment-summary {
  background: #f5f7fa;
  padding: 10px;
  border-radius: 4px;
  margin-top: 15px;
}

.amount {
  color: #f56c6c;
  font-weight: bold;
  display: inline-block;
  width: 120px;
  text-align: left;
}

.form-actions {
  text-align: center;
  margin-top: 20px;
}


.el-table__footer-wrapper {
  position: sticky !important;
  bottom: 0;
  background: white;
  display: table-footer-group !important;
}

/* 左表格 - 默认铺满 */
.table-left {
  flex: 1 1 100%;
  height: 100%;
  overflow: auto;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  min-width: 0; /* 防止内容溢出 */
}

/* 右抽屉表格 - 初始隐藏 */
.table-drawer {
  flex: 0 0 auto;
  height: 100%;
  width: 0;
  background: #fff;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  z-index: 10;
  overflow: hidden;
}

/* 抽屉打开状态 */
.table-drawer.open {
  flex: 0 0 40%; /* 固定宽度 */
  min-width: 400px;
}

.drawer-content {
  height: 100%;
  width: 100%;
  overflow: auto;
  box-sizing: border-box;
}


.form-grid {
  display: flex;
  flex-direction: column;
}

.form-main {
  margin-bottom: 10px;
}


.primary-actions {
  display: flex;
  gap: 10px;
}

.form-grid {
  display: flex;
  flex-direction: column;
}

.form-main {
  margin-bottom: 10px;
}

/* 新增底部输入盒子样式 */
.bottom-input-box {
  padding: 15px;
  background: #f8f8f9;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}


/deep/ .el-dialog__header {
  padding: 18px;
  background-color: #007bb0;
}

/deep/ .el-dialog__title {
  font-size: 18px;
  color: #fff;
}

/deep/ .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}

/deep/ .el-input.is-disabled .el-input__inner {
  color: #87898f;
}

/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #87898f;
}

.dialog {
  .addUnitDialog {
    .tabs {
      /deep/ .el-select > .el-input {
        width: 172px;
      }

      /deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner {
        width: 172px;
      }

      /deep/ .el-form-item__content {
        display: flex;

        span {
          font-size: 12px;
        }
      }

      .oneLine {
        width: 524px;
        // background-color: indianred;
      }
    }

    /deep/ .el-dialog__title {
      font-size: 15px;
    }

    /deep/ .el-table {
      font-size: 15px;
    }
  }

  .patient-dialog {
    .tabs {
      /deep/ .el-select > .el-input {
        width: 172px;
      }

      /deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner {
        width: 172px;
      }

      /deep/ .el-form-item__content {
        display: flex;

        span {
          font-size: 12px;
        }
      }

      .oneLine {
        width: 524px;
        // background-color: indianred;
      }
    }

    /deep/ .el-dialog__title {
      font-size: 15px;
    }

    /deep/ .el-table {
      font-size: 15px;
    }
  }
}


/* Vue 2 深度选择器写法 */
.custom-table /deep/ .el-table--border {
  border: 1px solid #e6e6e6;
}

.custom-table /deep/ .el-table__header th,
.custom-table /deep/ .el-table__body td {
  border-right: 1px solid #e6e6e6;
  border-bottom: 1px solid #e6e6e6;
}

.custom-table /deep/ .el-table__header th {
  background-color: #f5f7fa; /* 表头背景色 */
}

.data-row {
  display: flex;
  margin-bottom: 12px;
  align-items: center;
}

.label {
  width: 70px;
  font-size: 13px;
}

.el-input {
  flex: 1;
}


.side-panel {
  width: 240px;
  padding: 10px;
  background: #f5f7fa;
}

.registration-box {
  background: white;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  padding: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.data-row {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.label {
  width: 70px;
  font-size: 13px;
  color: #ffffff;
  margin-right: 4px;
}

.el-input {
  flex: 1;
}

.el-input.is-disabled .el-input__inner {
  background-color: #f5f5f5;
  color: #666;
}

/* 新增样式 */
.register-group {
  width: 50%;
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

/* 调整原有分隔线位置 */
.divider-line {
  width: 100%;
  margin: 12px 0 8px;
}

/* 强制同行显示 */
.register-type + .clinic-room {
  margin-left: -8px; /* 补偿间距 */
}

.divider-line {
  height: 1px;
  background-color: #ebeef5;
  margin: 15px 10px 0;
}

.el-form-item {
  margin-bottom: 5px;
}

.age-unit {
  margin: 0 5px;
  color: #ffffff;
  font-size: 12px;
}

.MedicenCata {
  height: 100%;
  width: 100%;

  .header {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 40px;
    background-color: #efefef;
    padding: 4px;

    .header-icon {
      width: 100%;
      display: flex;
      align-items: center;
    }
  }

}
</style>